package com.stackfarm.controller;

import com.stackfarm.fvcommon.requests.RegisterReq;
import com.stackfarm.fvcommon.result.ResultBean;
import com.stackfarm.fvservice.service.user.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户信息类")
@RestController
@RequestMapping("/user")
public class UsersController {
    @Autowired
    private UsersService usersService;
    @ApiOperation("用户登录")
    @PostMapping("/login")
    public ResultBean<?> login(String username, String password) {
        return usersService.login(username, password);
    }

    @ApiOperation("用户退出")
    @GetMapping("/logout")
    public ResultBean<?> doLogout() {
        return usersService.logout();
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public ResultBean<?> register(@RequestBody RegisterReq registerReq) {
        return usersService.register(registerReq.getUsername(), registerReq.getPassword(), registerReq.getIcode());
    }
}
